import java.util.Optional;
import java.util.Scanner;

public class AG3 {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		long b = scan.nextLong();
		if (a < b) {
			long t = a;
			a = b;
			b = t;
		}
		System.out.println(a - b - (a % (a - b)));
		scan.close();
	}
}
